<?php
/*
Module Group: mall
Module Group Name: 微商城
Description: 微商城用于购物
Version: 1.0
Iconurl: http://www.happyidea.com.cn/resource/wx_icon/default.png
Author: holiny
Modules: mall
Display: 1
*/

class mallModule extends Module {
	
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp('mall', 'mall');
	}
	
	/*
	 * 激活创建数据库
	*/
	public function activate() {
		Module::importSQL (module_sql_path('mall'));
	}
	
	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		switch ($method) {
			case 'getMall':
				$id = $param->id;
				$qId = $param->qId;
				$miUId = $param->miUId;
				if (!isset($id)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (isset($param->rootId)) {
					$rootId = $param->rootId;
				} else {
					$rootId = NULL;
				}
				if (!isset($param->start)) {
					$start = 0;
				} else {
					$start = $param->start;
				}
				if (!isset($param->start)) {
					$start = 0;
				} else {
					$start = $param->start;
				}
				if (isset($param->saleSourceUId)) {
					$saleSourceUId = $param->saleSourceUId;
				} else {
					$saleSourceUId = NULL;
				}
				if (isset($param->lastShareUId)) {
					$lastShareUId = $param->lastShareUId;
				} else {
					$lastShareUId = NULL;
				}
				if (isset($param->visitId)) {
					$visitId = $param->visitId;
				} else {
					$visitId = NULL;
				}
//				mall::getMall($id, $start, $rootId,$qId,$miUId);
				mall::getMall($id, $start, $rootId,$qId,$miUId,$saleSourceUId,$visitId,$lastShareUId);
				break;
			case 'getInvoice':
				$userName = $user["userName"];
				$ctrl = $param->ctrl;
				$invoiceId = $param->invoiceId;
				if (!isset($ctrl) || !isset($invoiceId) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				mall::getInvoice($userName,$invoiceId,$ctrl);
				break;
			case 'addInvoice':
				$userName = $user['userName'];
				$title = $param->title;
				$contentTypeId = $param->contentTypeId;
				$methodId = $param->methodId;
				if (!isset($title) || !isset($contentTypeId)
						|| !isset($methodId) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (isset($param->titleName)) {
					$titleName = $param->titleName;
				} else {
					$titleName = "";
				}
				mall::addInvoice($userName, $title, $titleName, $contentTypeId, $methodId);
				break;
			case 'updateInvoice':
				$userName = $user['userName'];
				$title = $param->title;
				$contentTypeId = $param->contentTypeId;
				$methodId = $param->methodId;
				$invoiceId = $param->invoiceId;
				if (!isset($title) || !isset($contentTypeId)
						|| !isset($methodId) || !isset($invoiceId) || $userName == '') {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				if (isset($param->titleName)) {
					$titleName = $param->titleName;
				} else {
					$titleName = "";
				}
				mall::updateInvoice($invoiceId, $userName, $title, $titleName, $contentTypeId, $methodId);
				break;
		}
	}
}


$module = new mallModule();
Module::addModule($module);